package com.micro.app.controller;

import com.micro.app.repository.AppInfoRepository;
import com.micro.app.vo.AppInfoVo;
import com.micro.common.constant.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;

/**
 * @author pan.shun
 * @since 2022/7/18 17:16
 */
@RestController
@RequestMapping("/es")
public class EsController {

    @Autowired
    private AppInfoRepository repository;

    @GetMapping("/queryByName/{appName}")
    public R queryByName(@PathVariable String appName) {
        return R.success(repository.findByAppName(appName));
    }

    @GetMapping("/getAll")
    public R getAll() {
        return R.success(repository.findAll(Sort.by("createTime").ascending()));
    }


    @PostMapping("/save")
    public R save(@RequestBody AppInfoVo appInfoVo) {
        repository.save(appInfoVo);
        return R.success();
    }

    @GetMapping("/delete/{id}")
    public R delete(@PathVariable String id) {
        repository.deleteById(Long.valueOf(id));
        return R.success();
    }
}
